﻿/// <reference name="MicrosoftAjax.js"/>
/// <reference name="Dimok.Web.UI.JS.JQuery.VSDoc.js" assembly="Dimok.Web.UI" />
/// <reference name="Dimok.Web.UI.JS.MSAjaxExtentions.js" assembly="Dimok.Web.UI" />
Sys.Application.add_load(function() {
  var templ = Dimok.Templates;
  $J.editable.addInputType(templ.toString(templ.dropdown), {
    element: Dimok$DropDownTemplate,
    content: Dimok$DropDownTemplate$Fetch,
    buttons: Dimok$SubmitButtonTemplate
  })
  $J.editable.addInputType(templ.toString(templ.textline), {
    element: Dimok$TextTemplate,
    buttons: Dimok$SubmitButtonTemplate
  })
});
// **************************************************************************
Type.registerNamespace("Dimok");
Dimok.Templates = function (){
    if (arguments.length !== 0) throw Error.parameterCount();
    throw Error.notImplemented();
}
Dimok.Templates.prototype = { text: 0, dropdown: 1, textline: 2 }
Dimok.Templates.registerEnum("Dimok.Templates");

Dimok.Template = function() {
if (arguments.length !== 0) throw Error.parameterCount();
throw Error.notImplemented();
}
Dimok.Template.prototype = { text: 0, dropdown: 1, textline: 2 }
Dimok.Template.registerClass("Dimok.Template",motobankcorp.Component);
Dimok.Template.WireEvents = function(element) {
  return $J(element).click(Dimok$CancelBubbleHandler)
    .keypress(Dimok$CancelBubbleHandler)
    .keyup(Dimok$CancelBubbleHandler)
    .keydown(Dimok$CancelBubbleHandler);
  function Dimok$CancelBubbleHandler() { event.cancelBubble = true; }
}
function Dimok$BuildTemplate(parent, settings) {
  var template = Dimok.Accessorize(settings).get_type();
  $J(parent).html("");
  var control;
  if (Array.contains([Dimok.Templates.get_text(), Dimok.Templates.get_textline()], template)) {
    control = Dimok$TextTemplate.apply(parent, [settings]);
  } else if (template == Dimok.Templates.get_dropdown()) {
    control = Dimok$DropDownTemplate.apply(parent, [settings]);
    Dimok$DropDownTemplate$Fetch.apply(parent, ["", settings]);
  }
}
function Dimok$SubmitButtonTemplate(settings) {
  var input = $J('<input type="image" style="border:none;vertical-align:middle" src="/images/Buttons/check_green.gif" />');
  $J(this).append(input);
  return (input);
}
function Dimok$TextTemplate(settings) {
  var input = $J('<input style="vertical-align:middle;overflow:visible;width:90%" />');
  $J(this).append(input).css(settings.get_elementCss());
  return Dimok.Template.WireEvents(input);
}

function Dimok$DropDownTemplate(settings, original) {
  var select = $J('<select style="vertical-align:middle"  />');
  $J(this).append(select).css(settings.get_elementCss());
  return Dimok.Template.WireEvents(select);
}
function Dimok$DropDownTemplate$Fetch(string, settings, original) {
  if (settings.get_template().get_LookUpEntity()) {
    var data = {
      ID: settings.get_gridDataItem().get_dataItem()[settings.get_fieldUpdate()] || null,
      EntityType: settings.get_template().get_LookUpEntity(),
      TextField: settings.get_template().get_LookUpTextField(),
      ValueField: settings.get_template().get_LookUpValueField()
    };
    var methodName = "LookUp_List";
  }
  else {
    data = { StatusID: settings.get_gridDataItem().get_dataItem()[settings.get_fieldUpdate()] };
    methodName = "Status_List";
  }
  Dimok.Ajax({methodName:methodName,wsObject:settings.get_wsObject()}, data,Function.createDelegate(this, _cb));
  function _cb(json) {
    var This = this;
    $J.each(json.d, function() {
      var option = $J('<option />').val(this.v+"").append(this.t+"");
      $J('select', This).append(option);
      if (this.s) $J('select', This).val(this.v);
    });
  }
}
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();